package oop.conf;

import java.util.LinkedList;
import java.util.List;

public class Config {

	private String databaseHost = "localhost";
	private String databasePort = "3306";
	private String databaseName = "ocwiki";
	private String username = "root";
	private String password = "root";
	private String homeDir = "";
	private String actionPath = "/w";
	private String mainEntry = "/index.jsp";
	private String siteName = "OCWiki";
	private String tablePrefix = "tbl";
	private List<ModuleDescriptor> moduleDescriptors = new LinkedList<ModuleDescriptor>();
	private List<ActionDescriptor> actionDescriptors = new LinkedList<ActionDescriptor>();

	public String getDatabaseHost() {
		return databaseHost;
	}

	public void setDatabaseHost(String databaseHost) {
		this.databaseHost = databaseHost;
	}

	public String getDatabasePort() {
		return databasePort;
	}

	public void setDatabasePort(String databasePort) {
		this.databasePort = databasePort;
	}

	public String getDatabaseName() {
		return databaseName;
	}

	public void setDatabaseName(String databaseName) {
		this.databaseName = databaseName;
	}

	public String getUserName() {
		return username;
	}

	public void setUserName(String userName) {
		this.username = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getHomeDir() {
		return homeDir;
	}

	public void setHomeDir(String homeDir) {
		this.homeDir = homeDir;
	}

	public String getActionPath() {
		return actionPath;
	}

	public void setActionPath(String actionPath) {
		this.actionPath = actionPath;
	}

	public String getMainEntry() {
		return mainEntry;
	}

	public void setMainEntry(String mainEntry) {
		this.mainEntry = mainEntry;
	}

	public String getSiteName() {
		return siteName;
	}

	public void setSiteName(String siteName) {
		this.siteName = siteName;
	}
	
	public String getTablePrefix() {
		return tablePrefix;
	}
	
	public void setTablePrefix(String tablePrefix) {
		this.tablePrefix = tablePrefix;
	}

	public ActionDescriptor getActionDescriptor(String name) throws Exception {
		for (ActionDescriptor desc : actionDescriptors) {
			if (desc.getName().equals(name)) {
				return desc;
			}
		}
		return null;
	}
	
	public List<ModuleDescriptor> getModuleDescriptors() {
		return moduleDescriptors;
	}

	private static Config DEFAULT = null;
	
	public static Config get() {
		return DEFAULT;
	}
	
	public static void init(Config config) {
		if (DEFAULT != null) {
			throw new IllegalStateException("Already initialized.");
		}
		DEFAULT = config;
	}
	
}
